package com.ds.infrastructure.hyperspace.console.model.request.handler;

import com.ds.infrastructure.hyperspace.console.dto.handler.HandlerParamsDTO;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * @author: yaozhendong
 * @create: 2019-09-24 17:48
 **/
@Data
@NoArgsConstructor
public class HandlerParamsForm {
    @NotBlank
    private String name;
    @NotBlank
    private String type;
    @NotNull
    private Boolean required;
    @NotBlank
    private String description;
    @NotNull
    @Min(1)
    @ApiModelProperty(value = "参数顺序", example = "1")
    private Integer sequence;

    public static HandlerParamsDTO toDTO(HandlerParamsForm form) {
        HandlerParamsDTO handlerParamsDTO = new HandlerParamsDTO();
        handlerParamsDTO.setName(form.getName());
        handlerParamsDTO.setType(form.getType());
        handlerParamsDTO.setRequired(form.getRequired());
        handlerParamsDTO.setDescription(form.getDescription());
        handlerParamsDTO.setSequence(form.getSequence());
        return handlerParamsDTO;
    }

    public static HandlerParamsForm toVO(HandlerParamsDTO dto) {
        HandlerParamsForm handlerParamsForm = new HandlerParamsForm();
        handlerParamsForm.setName(dto.getName());
        handlerParamsForm.setType(dto.getType());
        handlerParamsForm.setRequired(dto.getRequired());
        handlerParamsForm.setDescription(dto.getDescription());
        handlerParamsForm.setSequence(dto.getSequence());
        return handlerParamsForm;
    }
}
